package com.abc.controller;


import com.abc.entity.Admin;
import com.abc.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "管理员管理")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据 ID 获取管理员", notes = "根据提供的 ID 返回单个管理员信息")
    public Admin getAdminById(@PathVariable @ApiParam(value = "要查询的管理员 ID", required = true) Integer id) {
        return adminService.getById(id);
    }

    @PostMapping
    @ApiOperation(value = "添加新管理员", notes = "根据提供的管理员信息创建新管理员")
    public boolean addAdmin(@RequestBody @ApiParam(value = "要添加的管理员对象", required = true) Admin admin) {
        return adminService.save(admin);
    }

    @PutMapping
    @ApiOperation(value = "更新管理员信息", notes = "根据提供的管理员信息更新现有管理员")
    public boolean updateAdmin(@RequestBody @ApiParam(value = "要更新的管理员对象", required = true) Admin admin) {
        return adminService.updateById(admin);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除管理员", notes = "根据提供的 ID 删除管理员")
    public boolean deleteAdmin(@PathVariable @ApiParam(value = "要删除的管理员 ID", required = true) Integer id) {
        return adminService.removeById(id);
    }
}